import { Swagger, Options } from '../interface';

export function formatLoader(options: Partial<Options> = {}, content: Partial<Swagger> = {}) {
  const result: Partial<Swagger> = {};
  
  Object.keys(content).forEach(key => {
    const item = content[key];
    const { regexp, replacement = '' } = options;
    const reg = new RegExp(regexp);

    Object.keys(item).forEach(subItem => {
      item[subItem].url = key;
      item[subItem].formatUrl = key.replace(reg, replacement);
    });

    result[key] = item;
  });

  return result;
};